"""knowledge_config table add config_type column

Revision ID: e788b6ece584
Revises: 5daae45cc6b5
Create Date: 2024-07-23 03:24:42.238649

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'e788b6ece584'
down_revision: Union[str, None] = '5daae45cc6b5'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

# 定义枚举类型
knowledge_config_type_enum = sa.Enum(
    'DOCUMENT', 'SHEET', 'IMAGE', name='knowledgeconfigtype')


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # 创建枚举类型
    knowledge_config_type_enum.create(op.get_bind(), checkfirst=True)
    op.add_column('knowledge_config', sa.Column(
        'config_type', knowledge_config_type_enum, nullable=False))
    # op.alter_column('messages', 'message_type',
    #            existing_type=sa.VARCHAR(length=50),
    #            type_=sa.Enum('MARKDOWN', 'TEXT', name='messagetype'),
    #            existing_nullable=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    # op.alter_column('messages', 'message_type',
    #                 existing_type=sa.Enum(
    #                     'MARKDOWN', 'TEXT', name='messagetype'),
    #                 type_=sa.VARCHAR(length=50),
    #                 existing_nullable=False)
    op.drop_column('knowledge_config', 'config_type')
    # 删除枚举类型
    knowledge_config_type_enum.drop(op.get_bind(), checkfirst=True)
    # ### end Alembic commands ###
